package com.mzwise.tunnel.wx.miniapp.immediateDelivery.result;

import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * <pre>
 * 运单信息返回结果对象
 * </pre>
 * @author <a href="https://github.com/mr-xiaoyu">xiaoyu</a>
 * @since 2019-11-26
 */
@Data
public class WxMaImmediateDeliveryOrderInfoResult implements Serializable {
  private static final JsonParser JSON_PARSER = new JsonParser();
  private static final long serialVersionUID = -9166603059965942285L;

  private Integer resultcode;

  private String resultmsg;

  private Integer fee;

  @SerializedName("deliverfee")
  private Integer deliverfee;

  @SerializedName("couponfee")
  private Integer couponfee;

  @SerializedName("tips")
  private Integer tips;

  @SerializedName("insurancefee")
  private Integer insurancefee;

  @SerializedName("distance")
  private Integer distance;

  @SerializedName("waybill_id")
  private String waybillId;

  @SerializedName("order_status")
  private Integer orderStatus;

  @SerializedName("finish_code")
  private Integer finishCode;

  @SerializedName("pickup_code")
  private Integer pickupCode;

  @SerializedName("dispatch_duration")
  private Integer dispatchDuration;

  public static WxMaImmediateDeliveryOrderInfoResult fromJson(String json) {
    return WxMaGsonBuilder.create().fromJson(json, WxMaImmediateDeliveryOrderInfoResult.class);
  }

  public static List<WxMaImmediateDeliveryOrderInfoResult> toList(String json) {
    JsonObject jsonObject = JSON_PARSER.parse(json).getAsJsonObject();
    return WxMaGsonBuilder.create().fromJson(jsonObject.get("order_list").toString(),
      new TypeToken<List<WxMaImmediateDeliveryOrderInfoResult>>() {
      }.getType());
  }
}
